From d00e5ca3b6ae736f00d924e133e053650cc5c59d Mon Sep 17 00:00:00 2001 From: Michal Skvely Date: Wed, 2 Dec 2020 15:13:33 +0100 Subject: [PATCH] Use IPv4 for health and API server when configured --- src/siri/api.c | 9 +++++++-- src/siri/health.c | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/siri/api.c b/src/siri/api.c index 32ce1849..724ab503 100644 --- a/src/siri/api.c +++ b/src/siri/api.c @@ -11,6 +11,7 @@ #include #include #include +#include #define API__HEADER_MAX_SZ 256 @@ -836,7 +837,11 @@ int siri_api_init(void) if (port == 0) return 0; - (void) uv_ip6_addr("::", (int) port, (struct sockaddr_in6 *) &addr); + if (siri.cfg->ip_support == IP_SUPPORT_IPV4ONLY) { + (void) uv_ip4_addr("0.0.0.0", (int) port, (struct sockaddr_in *) &addr); + } else { + (void) uv_ip6_addr("::", (int) port, (struct sockaddr_in6 *) &addr); + } api__settings.on_url = api__url_cb; api__settings.on_header_field = api__header_field_cb; @@ -850,7 +855,7 @@ int siri_api_init(void) (rc = uv_tcp_bind( &api__uv_server, (const struct sockaddr *) &addr, - 0)) || + (siri.cfg->ip_support == IP_SUPPORT_IPV6ONLY) ? UV_TCP_IPV6ONLY : 0)) || (rc = uv_listen( (uv_stream_t *) &api__uv_server, 128, diff --git a/src/siri/health.c b/src/siri/health.c index 7d4c5e73..1e9957ab 100644 --- a/src/siri/health.c +++ b/src/siri/health.c @@ -3,6 +3,7 @@ */ #include #include +#include #include #define OK_RESPONSE \ @@ -311,7 +312,11 @@ int siri_health_init(void) struct sockaddr_storage addr = {0}; uint16_t port = siri.cfg->http_status_port; - (void) uv_ip6_addr("::", (int) port, (struct sockaddr_in6 *) &addr); + if (siri.cfg->ip_support == IP_SUPPORT_IPV4ONLY) { + (void) uv_ip4_addr("0.0.0.0", (int) port, (struct sockaddr_in *) &addr); + } else { + (void) uv_ip6_addr("::", (int) port, (struct sockaddr_in6 *) &addr); + } health__uv_ok_buf = uv_buf_init(OK_RESPONSE, strlen(OK_RESPONSE)); @@ -336,7 +341,7 @@ int siri_health_init(void) (rc = uv_tcp_bind( &health__uv_server, (const struct sockaddr *) &addr, - 0)) || + (siri.cfg->ip_support == IP_SUPPORT_IPV6ONLY) ? UV_TCP_IPV6ONLY : 0)) || (rc = uv_listen( (uv_stream_t *) &health__uv_server, 128, -- 2.30.2